package com.ewzj.bigdata.mvp.ui.fragment

import android.content.Intent
import android.os.Bundle
import android.support.v7.widget.LinearLayoutManager
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.ewzj.bigdata.R
import com.ewzj.bigdata.app.extensions.dpToPx
import com.ewzj.bigdata.app.extensions.initcolor
import com.ewzj.bigdata.di.component.DaggerDecorateCompanyComponent
import com.ewzj.bigdata.di.module.DecorateCompanyModule
import com.ewzj.bigdata.mvp.contract.DecorateCompanyFragmentContract
import com.ewzj.bigdata.mvp.presenter.DecorateCompanyPresenter
import com.ewzj.bigdata.mvp.ui.adapter.NewItemdecCompanyAdapter
import com.jess.arms.base.BaseFragment
import com.jess.arms.di.component.AppComponent
import com.yqritc.recyclerviewflexibledivider.HorizontalDividerItemDecoration
import kotlinx.android.synthetic.main.fragment_decoratecompany.*

/**
 * author:zhangjing
 * 作用:
 * return:
 */
class DecorateCompanyFragment :BaseFragment<DecorateCompanyPresenter>(),DecorateCompanyFragmentContract.View,IFragmentloaddata{
    override fun initRecylerView(newItemdecCompanyAdapter: NewItemdecCompanyAdapter) {
        rvcompany.layoutManager=LinearLayoutManager(activity)
        if (rvcompany.adapter==null) {
            rvcompany.setAdapter(newItemdecCompanyAdapter)
            rvcompany.addItemDecoration(HorizontalDividerItemDecoration.Builder(activity).colorResId(R.color.colorf7).size(10.dpToPx(activity)).build())
        }
    }

    companion object {
        fun newInstance(): DecorateCompanyFragment {
            val fragment = DecorateCompanyFragment()
            val args = Bundle()
            fragment.arguments = args
            return fragment
        }
    }
    override fun setData(data: Any?) {

    }

    override fun initView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
        val view=inflater.inflate(R.layout.fragment_decoratecompany,null)
        return view
    }

    override fun setupFragmentComponent(appComponent: AppComponent?) {
        DaggerDecorateCompanyComponent.builder().appComponent(appComponent)
                .decorateCompanyModule(DecorateCompanyModule(this))
                .build()
                .inject(this)
    }

    override fun initData(savedInstanceState: Bundle?) {
        swipeRefreshLayout.initcolor()
        swipeRefreshLayout.setOnRefreshListener { mPresenter.loadFristPage() }
        mPresenter.initAdapter(rvcompany)
        mPresenter.loadFristPage()
    }

    override fun showLoading() {
        swipeRefreshLayout.isRefreshing=true
    }

    override fun launchActivity(intent: Intent?) {

    }

    override fun hideLoading() {
        swipeRefreshLayout.isRefreshing=false
    }

    override fun killMyself() {

    }

    override fun showMessage(message: String?) {

    }

    override fun searchData(keyword: String) {
        mPresenter.keyword=keyword
        mPresenter.loadFristPage()
    }
}